import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import "../../components" as Components
import "../../styles" as Styles

ScrollView {
    id: vehicleDetailsView

    // 自定义属性
    property var agv: null
    property bool editMode: false

    // 信号
    signal agvModified(var agv)

    clip: true

    ScrollBar.horizontal.policy: ScrollBar.AlwaysOff

    ScrollBar.vertical: ScrollBar {
        id: vbar
        width: 8
        policy: ScrollBar.AsNeeded
        anchors.right: parent.right
        anchors.top: parent.top
        anchors.bottom: parent.bottom

        contentItem: Rectangle {
            implicitWidth: 8
            radius: 4
            color: vbar.pressed ? Styles.Theme.primary :
                   vbar.hovered ? Styles.Theme.textSecondary :
                   Styles.Theme.textTertiary
            opacity: vbar.pressed ? 0.9 : vbar.hovered ? 0.7 : 0.5

            Behavior on color { ColorAnimation { duration: 150 } }
            Behavior on opacity { NumberAnimation { duration: 150 } }
        }

        background: Rectangle {
            color: Styles.Theme.backgroundSecondary
            opacity: 0.3
            radius: 4
        }
    }

    ColumnLayout {
        width: vehicleDetailsView.width - 12  // 为右侧滚动条留出空间 (8px + 4px margin)
        spacing: Styles.Theme.spacingNormal

        // 基本信息区域
        Rectangle {
            Layout.fillWidth: true
            implicitHeight: basicInfoColumn.implicitHeight + Styles.Theme.spacingNormal * 2
            color: Styles.Theme.backgroundSecondary
            border.color: Styles.Theme.border
            border.width: 1
            radius: Styles.Theme.radiusSmall

            ColumnLayout {
                id: basicInfoColumn
                anchors.left: parent.left
                anchors.right: parent.right
                anchors.top: parent.top
                anchors.margins: Styles.Theme.spacingNormal
                spacing: Styles.Theme.spacingSmall

                Text {
                    text: qsTr("基本信息")
                    color: Styles.Theme.textPrimary
                    font.pixelSize: Styles.Theme.fontSizeNormal
                    font.weight: Styles.Theme.fontWeightMedium
                }

                GridLayout {
                    Layout.fillWidth: true
                    columns: 2
                    rowSpacing: Styles.Theme.spacingSmall
                    columnSpacing: Styles.Theme.spacingNormal

                    Text {
                        text: qsTr("AGV ID:")
                        color: Styles.Theme.textSecondary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                    }
                    Text {
                        text: agv ? agv.id : ""
                        color: Styles.Theme.textPrimary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                        font.weight: Styles.Theme.fontWeightMedium
                        Layout.fillWidth: true
                    }

                    Text {
                        text: qsTr("任务状态:")
                        color: Styles.Theme.textSecondary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                    }
                    Rectangle {
                        Layout.preferredWidth: 100
                        Layout.preferredHeight: 24
                        radius: 12
                        color: getTaskStatusColor(agv ? agv.taskStatus : null)

                        RowLayout {
                            anchors.centerIn: parent
                            spacing: 4

                            Text {
                                text: getTaskStatusIcon(agv ? agv.taskStatus : null)
                                color: Styles.Theme.textOnPrimary
                                font.pixelSize: 12
                            }

                            Text {
                                text: getTaskStatusText(agv ? agv.taskStatus : null)
                                color: Styles.Theme.textOnPrimary
                                font.pixelSize: 11
                            }
                        }
                    }

                    Text {
                        text: qsTr("注册时间:")
                        color: Styles.Theme.textSecondary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                    }
                    Text {
                        text: formatTime(agv ? agv.registerTime : null)
                        color: Styles.Theme.textSecondary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                    }
                }
            }
        }

        // 位置和导航信息
        Rectangle {
            Layout.fillWidth: true
            implicitHeight: positionInfoColumn.implicitHeight + Styles.Theme.spacingNormal * 2
            color: Styles.Theme.backgroundSecondary
            border.color: Styles.Theme.border
            border.width: 1
            radius: Styles.Theme.radiusSmall

            ColumnLayout {
                id: positionInfoColumn
                anchors.left: parent.left
                anchors.right: parent.right
                anchors.top: parent.top
                anchors.margins: Styles.Theme.spacingNormal
                spacing: Styles.Theme.spacingSmall

                Text {
                    text: qsTr("位置与导航")
                    color: Styles.Theme.textPrimary
                    font.pixelSize: Styles.Theme.fontSizeNormal
                    font.weight: Styles.Theme.fontWeightMedium
                }

                GridLayout {
                    Layout.fillWidth: true
                    columns: 2
                    rowSpacing: Styles.Theme.spacingSmall
                    columnSpacing: Styles.Theme.spacingNormal

                    Text {
                        text: qsTr("当前位置:")
                        color: Styles.Theme.textSecondary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                    }
                    Text {
                        text: formatPosition(agv ? agv.x : null, agv ? agv.y : null)
                        color: Styles.Theme.textPrimary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                        Layout.fillWidth: true
                    }

                    Text {
                        text: qsTr("朝向角度:")
                        color: Styles.Theme.textSecondary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                    }
                    Text {
                        text: agv ? qsTr("%1°").arg((agv.angle || 0).toFixed(1)) : ""
                        color: Styles.Theme.textPrimary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                    }

                    Text {
                        text: qsTr("当前站点:")
                        color: Styles.Theme.textSecondary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                    }
                    Text {
                        text: agv ? agv.currentStation || qsTr("路径中") : ""
                        color: Styles.Theme.textPrimary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                    }

                    Text {
                        text: qsTr("目标站点:")
                        color: Styles.Theme.textSecondary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                    }
                    Text {
                        text: agv ? agv.targetStation || qsTr("无") : ""
                        color: Styles.Theme.textPrimary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                    }

                    Text {
                        text: qsTr("当前地图:")
                        color: Styles.Theme.textSecondary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                    }
                    Text {
                        text: formatMapName(agv ? agv.currentMap : "")
                        color: Styles.Theme.textPrimary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                        Layout.fillWidth: true
                    }

                    Text {
                        text: qsTr("当前楼层:")
                        color: Styles.Theme.textSecondary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                    }
                    Text {
                        text: formatFloor(agv ? agv.currentMap : "")
                        color: Styles.Theme.textPrimary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                    }

                    Text {
                        text: qsTr("导航状态:")
                        color: Styles.Theme.textSecondary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                    }
                    Rectangle {
                        Layout.preferredWidth: 110
                        Layout.preferredHeight: 24
                        radius: 12
                        color: getAgvStatusColor(agv ? agv.status : "")

                        RowLayout {
                            anchors.centerIn: parent
                            spacing: 4

                            Text {
                                text: getAgvStatusIcon(agv ? agv.status : "")
                                color: Styles.Theme.textOnPrimary
                                font.pixelSize: 12
                            }

                            Text {
                                text: getAgvStatusText(agv ? agv.status : "")
                                color: Styles.Theme.textOnPrimary
                                font.pixelSize: 11
                            }
                        }
                    }

                    Text {
                        text: qsTr("定位置信度:")
                        color: Styles.Theme.textSecondary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                    }
                    Text {
                        text: formatConfidence(agv ? agv.confidence : null)
                        color: Styles.Theme.textPrimary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                    }

                    Text {
                        text: qsTr("行驶速度:")
                        color: Styles.Theme.textSecondary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                    }
                    Text {
                        text: agv ? qsTr("%1 m/s").arg((agv.speed || 0).toFixed(2)) : ""
                        color: Styles.Theme.textPrimary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                    }
                }
            }
        }

        // 电池和电源信息
        Rectangle {
            Layout.fillWidth: true
            implicitHeight: batteryInfoColumn.implicitHeight + Styles.Theme.spacingNormal * 2
            color: Styles.Theme.backgroundSecondary
            border.color: Styles.Theme.border
            border.width: 1
            radius: Styles.Theme.radiusSmall

            ColumnLayout {
                id: batteryInfoColumn
                anchors.left: parent.left
                anchors.right: parent.right
                anchors.top: parent.top
                anchors.margins: Styles.Theme.spacingNormal
                spacing: Styles.Theme.spacingSmall

                Text {
                    text: qsTr("电池状态")
                    color: Styles.Theme.textPrimary
                    font.pixelSize: Styles.Theme.fontSizeNormal
                    font.weight: Styles.Theme.fontWeightMedium
                }

                // 电池电量进度条
                RowLayout {
                    Layout.fillWidth: true

                    Text {
                        text: qsTr("电量:")
                        color: Styles.Theme.textSecondary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                        Layout.preferredWidth: 80
                    }

                    Rectangle {
                        Layout.fillWidth: true
                        Layout.preferredHeight: 20
                        color: Styles.Theme.backgroundAlternate
                        radius: 10
                        border.color: Styles.Theme.border
                        border.width: 1

                        Rectangle {
                            anchors.left: parent.left
                            anchors.top: parent.top
                            anchors.bottom: parent.bottom
                            anchors.margins: 1
                            width: Math.max(0, Math.min(parent.width - 2, (agv ? agv.battery || 0 : 0) * (parent.width - 2) / 100))
                            color: getBatteryColor(agv ? agv.battery : 0)
                            radius: 9

                            Text {
                                anchors.centerIn: parent
                                text: qsTr("%1%").arg(agv ? Math.round(agv.battery || 0) : 0)
                                color: Styles.Theme.textOnPrimary
                                font.pixelSize: 10
                                visible: parent.width > 40
                            }
                        }
                    }

                    Text {
                        text: agv && agv.isCharging ? "⚡" : ""
                        color: Styles.Theme.warning
                        font.pixelSize: 16
                        visible: agv && agv.isCharging
                    }
                }

                GridLayout {
                    Layout.fillWidth: true
                    columns: 2
                    rowSpacing: Styles.Theme.spacingSmall
                    columnSpacing: Styles.Theme.spacingNormal

                    Text {
                        text: qsTr("电压:")
                        color: Styles.Theme.textSecondary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                    }
                    Text {
                        text: agv ? qsTr("%1 V").arg((agv.voltage || 0).toFixed(1)) : ""
                        color: Styles.Theme.textSecondary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                    }

                    Text {
                        text: qsTr("电流:")
                        color: Styles.Theme.textSecondary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                    }
                    Text {
                        text: agv ? qsTr("%1 A").arg((agv.current || 0).toFixed(2)) : ""
                        color: Styles.Theme.textSecondary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                    }

                    Text {
                        text: qsTr("充电状态:")
                        color: Styles.Theme.textSecondary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                    }
                    Text {
                        text: agv && agv.isCharging ? qsTr("充电中") : qsTr("未充电")
                        color: agv && agv.isCharging ? Styles.Theme.warning : Styles.Theme.textSecondary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                    }

                    Text {
                        text: qsTr("预计续航:")
                        color: Styles.Theme.textSecondary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                    }
                    Text {
                        text: agv ? qsTr("%1 小时").arg((agv.estimatedRuntime || 0).toFixed(1)) : ""
                        color: Styles.Theme.textSecondary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                    }
                }
            }
        }

        // 任务信息
        Rectangle {
            Layout.fillWidth: true
            implicitHeight: taskInfoColumn.implicitHeight + Styles.Theme.spacingNormal * 2
            color: Styles.Theme.backgroundSecondary
            border.color: Styles.Theme.border
            border.width: 1
            radius: Styles.Theme.radiusSmall

            ColumnLayout {
                id: taskInfoColumn
                anchors.left: parent.left
                anchors.right: parent.right
                anchors.top: parent.top
                anchors.margins: Styles.Theme.spacingNormal
                spacing: Styles.Theme.spacingSmall

                Text {
                    text: qsTr("任务信息")
                    color: Styles.Theme.textPrimary
                    font.pixelSize: Styles.Theme.fontSizeNormal
                    font.weight: Styles.Theme.fontWeightMedium
                }

                GridLayout {
                    Layout.fillWidth: true
                    columns: 2
                    rowSpacing: Styles.Theme.spacingSmall
                    columnSpacing: Styles.Theme.spacingNormal

                    Text {
                        text: qsTr("当前任务:")
                        color: Styles.Theme.textSecondary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                    }
                    Text {
                        text: agv ? agv.currentTask || qsTr("无") : ""
                        color: agv && agv.currentTask ? Styles.Theme.textPrimary : Styles.Theme.textSecondary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                        Layout.fillWidth: true
                    }

                    Text {
                        text: qsTr("任务进度:")
                        color: Styles.Theme.textSecondary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                        visible: !!(agv && agv.currentTask)
                    }
                    Rectangle {
                        Layout.fillWidth: true
                        Layout.preferredHeight: 16
                        color: Styles.Theme.backgroundAlternate
                        radius: 8
                        border.color: Styles.Theme.border
                        border.width: 1
                        visible: !!(agv && agv.currentTask)

                        Rectangle {
                            anchors.left: parent.left
                            anchors.top: parent.top
                            anchors.bottom: parent.bottom
                            anchors.margins: 1
                            width: Math.max(0, Math.min(parent.width - 2, (agv ? agv.taskProgress || 0 : 0) * (parent.width - 2) / 100))
                            color: Styles.Theme.info
                            radius: 7

                            Text {
                                anchors.centerIn: parent
                                text: qsTr("%1%").arg(agv ? Math.round(agv.taskProgress || 0) : 0)
                                color: Styles.Theme.textOnPrimary
                                font.pixelSize: 9
                                visible: parent.width > 30
                            }
                        }
                    }

                    Text {
                        text: qsTr("总完成任务:")
                        color: Styles.Theme.textSecondary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                    }
                    Text {
                        text: agv ? agv.completedTasks || "0" : ""
                        color: Styles.Theme.textSecondary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                    }

                    Text {
                        text: qsTr("总运行时间:")
                        color: Styles.Theme.textSecondary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                    }
                    Text {
                        text: agv ? formatDuration(agv.totalRuntime) : ""
                        color: Styles.Theme.textSecondary
                        font.pixelSize: Styles.Theme.fontSizeSmall
                    }
                }
            }
        }

        // 传感器状态
        Rectangle {
            Layout.fillWidth: true
            implicitHeight: sensorInfoColumn.implicitHeight + Styles.Theme.spacingNormal * 2
            color: Styles.Theme.backgroundSecondary
            border.color: Styles.Theme.border
            border.width: 1
            radius: Styles.Theme.radiusSmall

            ColumnLayout {
                id: sensorInfoColumn
                anchors.left: parent.left
                anchors.right: parent.right
                anchors.top: parent.top
                anchors.margins: Styles.Theme.spacingNormal
                spacing: Styles.Theme.spacingSmall

                Text {
                    text: qsTr("传感器状态")
                    color: Styles.Theme.textPrimary
                    font.pixelSize: Styles.Theme.fontSizeNormal
                    font.weight: Styles.Theme.fontWeightMedium
                }

                GridLayout {
                    Layout.fillWidth: true
                    columns: 4
                    rowSpacing: Styles.Theme.spacingSmall
                    columnSpacing: Styles.Theme.spacingNormal

                    // 激光雷达
                    ColumnLayout {
                        spacing: 2

                        Text {
                            text: qsTr("激光雷达")
                            color: Styles.Theme.textSecondary
                            font.pixelSize: Styles.Theme.fontSizeSmall
                        }

                        Rectangle {
                            width: 12
                            height: 12
                            radius: 6
                            color: getSensorStatusColor(agv ? agv.sensors?.lidar : false)
                        }
                    }

                    // 摄像头
                    ColumnLayout {
                        spacing: 2

                        Text {
                            text: qsTr("摄像头")
                            color: Styles.Theme.textSecondary
                            font.pixelSize: Styles.Theme.fontSizeSmall
                        }

                        Rectangle {
                            width: 12
                            height: 12
                            radius: 6
                            color: getSensorStatusColor(agv ? agv.sensors?.camera : false)
                        }
                    }

                    // 超声波
                    ColumnLayout {
                        spacing: 2

                        Text {
                            text: qsTr("超声波")
                            color: Styles.Theme.textSecondary
                            font.pixelSize: Styles.Theme.fontSizeSmall
                        }

                        Rectangle {
                            width: 12
                            height: 12
                            radius: 6
                            color: getSensorStatusColor(agv ? agv.sensors?.ultrasonic : false)
                        }
                    }

                    // 急停按钮
                    ColumnLayout {
                        spacing: 2

                        Text {
                            text: qsTr("急停按钮")
                            color: Styles.Theme.textSecondary
                            font.pixelSize: Styles.Theme.fontSizeSmall
                        }

                        Rectangle {
                            width: 12
                            height: 12
                            radius: 6
                            color: agv && agv.emergencyStop ? Styles.Theme.danger : Styles.Theme.success
                        }
                    }
                }
            }
        }

        // 错误信息（如果有）
        Rectangle {
            Layout.fillWidth: true
            implicitHeight: errorInfoColumn.implicitHeight + Styles.Theme.spacingNormal * 2
            color: Styles.Theme.backgroundSecondary
            border.color: Styles.Theme.danger
            border.width: 1
            radius: Styles.Theme.radiusSmall
            visible: agv && agv.status === "error" && agv.errorMessage

            ColumnLayout {
                id: errorInfoColumn
                anchors.left: parent.left
                anchors.right: parent.right
                anchors.top: parent.top
                anchors.margins: Styles.Theme.spacingNormal
                spacing: Styles.Theme.spacingSmall

                RowLayout {
                    Layout.fillWidth: true

                    Text {
                        text: "⚠️"
                        font.pixelSize: Styles.Theme.fontSizeNormal
                    }

                    Text {
                        text: qsTr("错误信息")
                        color: Styles.Theme.danger
                        font.pixelSize: Styles.Theme.fontSizeNormal
                        font.weight: Styles.Theme.fontWeightMedium
                        Layout.fillWidth: true
                    }
                }

                Rectangle {
                    Layout.fillWidth: true
                    implicitHeight: errorText.implicitHeight + 16
                    color: Styles.Theme.danger
                    opacity: 0.1
                    radius: Styles.Theme.radiusSmall

                    Text {
                        id: errorText
                        anchors.left: parent.left
                        anchors.right: parent.right
                        anchors.top: parent.top
                        anchors.margins: 8
                        text: agv ? agv.errorMessage || "" : ""
                        color: Styles.Theme.danger
                        font.pixelSize: Styles.Theme.fontSizeSmall
                        wrapMode: Text.WordWrap
                    }
                }
            }
        }
    }

    // 辅助函数
    function getTaskStatusColor(status) {
        var normalized = status === null || status === undefined ? -1 : Number(status);
        switch (normalized) {
        case 2: return Styles.Theme.info;        // Running
        case 3: return Styles.Theme.warning;     // Suspended
        case 4: return Styles.Theme.success;     // Completed
        case 5: return Styles.Theme.danger;      // Failed
        case 6: return Styles.Theme.textSecondary; // Canceled
        case 1: return Styles.Theme.warning;     // Waiting
        case 0: return Styles.Theme.textSecondary; // None
        default: return Styles.Theme.textSecondary;
        }
    }

    function getTaskStatusText(status) {
        var normalized = status === null || status === undefined ? -1 : Number(status);
        switch (normalized) {
        case 0: return qsTr("无任务");
        case 1: return qsTr("等待中");
        case 2: return qsTr("执行中");
        case 3: return qsTr("已暂停");
        case 4: return qsTr("已完成");
        case 5: return qsTr("失败");
        case 6: return qsTr("已取消");
        default: return qsTr("未知");
        }
    }

    function getTaskStatusIcon(status) {
        var normalized = status === null || status === undefined ? -1 : Number(status);
        switch (normalized) {
        case 0: return "－";
        case 1: return "⏳";
        case 2: return "⚙";
        case 3: return "⏸";
        case 4: return "✓";
        case 5: return "⚠";
        case 6: return "✕";
        default: return "?";
        }
    }

    function getAgvStatusColor(status) {
        switch(status) {
        case "running":
        case "executing":
            return Styles.Theme.info;
        case "idle":
            return Styles.Theme.success;
        case "charging":
            return Styles.Theme.warning;
        case "blocked":
        case "paused":
            return Styles.Theme.warning;
        case "error":
            return Styles.Theme.danger;
        case "offline":
            return Styles.Theme.textSecondary;
        default:
            return Styles.Theme.textSecondary;
        }
    }

    function getAgvStatusText(status) {
        switch(status) {
        case "running": return qsTr("导航中");
        case "executing": return qsTr("执行中");
        case "idle": return qsTr("空闲");
        case "charging": return qsTr("充电中");
        case "blocked": return qsTr("受阻");
        case "paused": return qsTr("已暂停");
        case "error": return qsTr("故障");
        case "offline": return qsTr("离线");
        default: return qsTr("未知");
        }
    }

    function getAgvStatusIcon(status) {
        switch(status) {
        case "running": return "➤";
        case "executing": return "⚙";
        case "idle": return "✓";
        case "charging": return "⚡";
        case "blocked": return "⛔";
        case "paused": return "⏸";
        case "error": return "⚠";
        case "offline": return "⊘";
        default: return "?";
        }
    }

    function getBatteryColor(battery) {
        var level = battery || 0
        if (level > 50) return Styles.Theme.success
        if (level > 20) return Styles.Theme.warning
        return Styles.Theme.danger
    }

    function getSensorStatusColor(status) {
        return status ? Styles.Theme.success : Styles.Theme.danger
    }

    function formatPosition(x, y) {
        if (x == null || y == null || x === undefined || y === undefined) return qsTr("未知位置")
        return qsTr("(%1, %2)").arg(x.toFixed(1)).arg(y.toFixed(1))
    }

    function formatMapName(mapName) {
        if (!mapName) {
            return qsTr("未知");
        }
        return mapName;
    }

    function formatFloor(mapName) {
        if (!mapName || typeof GlobalMapViewModel === "undefined" || !GlobalMapViewModel) {
            return qsTr("未知");
        }
        var floor = GlobalMapViewModel.getFloorForMap(mapName);
        if (floor === null || floor === undefined || floor < 0) {
            return qsTr("未知");
        }
        return qsTr("第%1层").arg(floor);
    }

    function formatConfidence(value) {
        if (value === null || value === undefined) return qsTr("未知");
        var numeric = Number(value);
        if (isNaN(numeric)) return qsTr("未知");
        var clamped = Math.max(0, Math.min(1, numeric));
        return qsTr("%1%").arg((clamped * 100).toFixed(1));
    }

    function formatTime(timestamp) {
        if (!timestamp) return qsTr("未设置")
        return new Date(timestamp).toLocaleString()
    }

    function formatDuration(seconds) {
        if (!seconds) return qsTr("0小时")
        var hours = Math.floor(seconds / 3600)
        var minutes = Math.floor((seconds % 3600) / 60)
        return qsTr("%1小时%2分钟").arg(hours).arg(minutes)
    }
}
